<#include "/layout/header.ftl" />
<#import "/include/ui.ftl" as blue />

<script src="${rc_path}/js/jquery/jquery-treetable.js"></script>
<script src="${rc_path}/js/jquery/jquery-plupload.js"></script>

<script>
$(function()
{
	$.upload(
	{
		button: "#btn_upload",
		type: 5,
		progress: "#prog_upload",
		url: "/pan/file_data_upload",
		div: "#div_progress",
		param: {folderId: "${parentId!"0"}"},
		result: function(up, file, o)
		{
			$.successAlert("上传成功", "save_success()", 2000);
		}
	});
});

function add_click()
{
	_file = "1";
	$("#div_model_form").setObject({parentId: "${parentId!}"});
	$("#div_model_name").modal("open");
}

function edit_click(id, name, file)
{
	_file = file;
	var obj = {id: id, name: name, parentId: "${parentId!}"};
	$("#div_model_form").setObject(obj);
	$("#div_model_name").modal("open");
}

function save_click()
{
	var url = (_file == '1' ? "/pan/folder_save" : "/pan/file_data_save");
	$.simpleValid("#div_model_form", function(obj)
	{
		$.simpleAjax(url, obj, function(o)
		{
			$.successAlert("保存成功", "save_success()", 2000);
		});
	});
}
function save_success()
{
	window.location = "${path}/pan/folder_list?parentId=${parentId!}";
}
function delete_click(id, file)
{
	var url = (file == '1' ? "/pan/folder_state" : "/pan/file_data_state");
	$.simpleConfirm("确定删除？", function(ops)
	{
		$.simpleAjax(url, {id: id, state: 1}, function(o)
		{
			$.successAlert("删除成功", "save_success()", 2000);
		});
	});
}

function tree_click(id, type, file)
{
	_id = id;
	_type = type;
	_file = file;
	/*$("#tbl_tree tr").show();
	if (type == 1)
	{
		$("#tree_tr_" + id).hide();
	}*/
	$("#div_model").modal("open");
}
function tree_onselect(id, parentId, name)
{
	if (_file == '1' && _id == id)
	{
		$.errorAlert("不能选同个目录");
		return;
	}

	var url = (_file == '1' ? "/pan/folder_operate" : "/pan/file_data_operate");
	var obj = {srcId: _id, destId: id, type: _type};
	$.simpleAjax(url, obj, function(o)
	{
		$.successAlert("操作成功", "save_success()", 2000);
	});
}

var _id = null;
var _type = null;
var _file = null;

</script>

<div class="am-g am-cf am-margin-top am-margin-bottom">
	<div class="am-u-md-6">
		<ol class="am-breadcrumb am-breadcrumb-slash">
			<li><a href="${path}/pan/folder_list" class="am-icon-home">根目录</a></li>
			<#if pathList??>
			<#list pathList as vo>
				<#if vo_index == pathList?size - 1>
					<li class="am-active">${vo.name!}</li>
				<#else>
			    	<li><a href="${path}/pan/folder_list?parentId=${vo.id}">${vo.name!}</a></li>
				</#if>
			</#list>
			</#if>
		</ol>
	</div>

	<div class="am-u-sm-5 am-u-end am-text-right">
		<div class="am-btn-group">
			<a href="javascript:void(0)" onclick="add_click()" class="am-btn am-btn-primary am-radius">创建目录</a>
			<a href="javascript:void(0)" id="btn_upload" class="am-btn am-btn-danger am-radius">上传文件</a>
		</div>
	</div>
</div>

<div class="am-g" id="div_grid">
	<div class="am-u-sm-12">
		<table class="am-table am-table-striped am-table-hover">
			<thead>
			<tr>
				<th width="80">序号</th>
				<th>目录名称</th>
				<th width="250">创建时间</th>
				<th width="100">文件数</th>
				<th width="150">文件大小</th>
				<th width="300">操作</th>
			</tr>
			</thead>
			<tbody>
			<#list folderList as vo>
			<tr>
				<td>${vo_index+1}</td>
				<td>
					<a class="am-icon-folder-o am-icon-sm"></a>
					<a href="${path}/pan/folder_list?parentId=${vo.id!}">${vo.name!}</a>
				</td>
				<td>${(vo.createTime?datetime)!}</td>
				<td >${vo.files!}</td>
				<td >${vo.fileSizeName!}</td>
				<td>
					<div class="am-btn-group">
						<a href="javascript:void(0)" onclick="edit_click('${vo.id!}', '${vo.name!}', '1')" class="am-btn am-btn-primary am-btn-sm am-radius">重命名</a>
						<a href="javascript:void(0)" onclick="tree_click('${vo.id!}', '1', '1')" class="am-btn am-btn-primary am-btn-sm am-radius">移动</a>
						<a href="javascript:void(0)" onclick="tree_click('${vo.id!}', '2', '1')" class="am-btn am-btn-primary am-btn-sm am-radius">复制</a>
						<a href="javascript:void(0)" onclick="delete_click('${vo.id!}', '1')" class="am-btn am-btn-danger am-btn-sm am-radius">删除</a>
					</div>
				</td>
			</tr>
			</#list>
			<#list fileList as vo>
			<tr>
				<td>${vo_index+1+folderList?size}</td>
				<td>
					<a class="am-icon-file-o am-icon-sm"></a>
					<a href="${vo.url!}" target="_blank">${vo.name!}</a>
				</td>
				<td>${(vo.createTime?datetime)!}</td>
				<td >${vo.files!"1"}</td>
				<td >${vo.fileSizeName!}</td>
				<td>
					<div class="am-btn-group">
						<a href="javascript:void(0)" onclick="edit_click('${vo.id!}', '${vo.name!}', '2')" class="am-btn am-btn-primary am-btn-sm am-radius">重命名</a>
						<a href="javascript:void(0)" onclick="tree_click('${vo.id!}', '1', '2')" class="am-btn am-btn-primary am-btn-sm am-radius">移动</a>
						<a href="javascript:void(0)" onclick="tree_click('${vo.id!}', '2', '2')" class="am-btn am-btn-primary am-btn-sm am-radius">复制</a>
						<a href="javascript:void(0)" onclick="delete_click('${vo.id!}', '2')" class="am-btn am-btn-danger am-btn-sm am-radius">删除</a>
					</div>
				</td>
			</tr>
			</#list>
			</tbody>
		</table>
	</div>
</div>

<div class="am-modal am-modal-no-btn" tabindex="-1" id="div_model_name">
	<div class="am-modal-dialog">
		<div class="am-modal-hd">
			目录名称
			<a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
		</div>
		<div class="am-modal-bd" id="div_model_form">
			<input type="hidden" name="id"/>
			<input type="hidden" name="parentId" value="${parentId!}"/>
			<div class="am-g">
				<div class="am-u-sm-12">
					<input type="text" name="name" placeholder="输入目录名称" class="am-form-field am-radius"  maxlength="100"  required/>
				</div>
			</div>
			<a href="javascript:void(0)" onclick="save_click()" class="am-btn am-btn-primary am-radius am-margin-top">保存</a>
		</div>
	</div>
</div>


<#include "/include/tree_dialog.ftl" />
<#include "/layout/footer.ftl" />